﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace BadassPhotoAlbum
{
    public partial class PhotoWizard : Form
    {
        private string photoName;
        private string photoDescription;
        private Boolean validFlag;
        private const int NAME_COUNT = 20;      // max char count for a photo name
        private const int DESCRIP_COUNT = 130;  // max char count for a photo desciption

        /// <summary>
        /// Constructor
        /// Sets up events and sets texts
        /// Written By: Steven Gonzalez & Adam Reaves
        /// </summary>
        public PhotoWizard(string photoname, string photodescription)
        {
            InitializeComponent();

            this.KeyDown += new KeyEventHandler(PhotoWizard_KeyDown);
            PhotoNameTextBox.KeyDown += new KeyEventHandler(PhotoNameTextBox_KeyDown);
            PhotoNameTextBox.TextChanged += new EventHandler(PhotoNameTextBox_TextChanged);
            PhotoDescriptionTextBox.KeyDown += new KeyEventHandler(PhotoDescriptionTextBox_KeyDown);
            PhotoDescriptionTextBox.TextChanged += new EventHandler(PhotoDescriptionTextBox_TextChanged);

            PhotoNameTextBox.Text = photoname;
            PhotoDescriptionTextBox.Text = photodescription;
        }

        /// <summary>
        /// Captures keyboard input and does certain actions according to what button is clicked
        /// Written By: Steven Gonzalez & Adam Reaves
        /// </summary>
        void PhotoWizard_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            {
                case Keys.Escape: //exit, clsoe the form
                    this.Close();
                    break;
            }
        }

        /// <summary>
        /// Captures keys input into a textbox and allows enter to accept the form
        /// Written By: Steven Gonzalez & Adam Reaves
        /// </summary>
        void PhotoDescriptionTextBox_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            {
                case Keys.Enter:
                    this.AcceptForm();
                    break;
            }
        }

        /// <summary>
        /// Captures keys input into text box and allows enter to accept the form
        /// Written By: Steven Gonzalez & Adam Reaves
        /// </summary>
        void PhotoNameTextBox_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            {
                case Keys.Enter:
                    this.AcceptForm();
                    break;
            }
        }

        /// <summary>
        /// Verifies all the user input data is correct
        /// Validates the form if so. Prompts user if not
        /// Written By: Steven Gonzalez & Adam Reaves
        /// </summary>
        private void AcceptForm()
        {
            photoDescription = PhotoDescriptionTextBox.Text;
            photoName = PhotoNameTextBox.Text;

            if (photoName.Trim() == "")
            {
                PhotoNameTooltip.Show("Name Must Contain At Least One Character", PhotoNameTextBox, 0, 0, 3000);
                return;
            }

            //gotten this far, must be vaid
            this.validFlag = true;

            this.Close();
        }

        /// <summary>
        /// Photo name property
        /// Returns string name.
        /// Written By: Steven Gonzalez & Adam Reaves
        /// </summary>
        public string PhotoName
        {
            get { return photoName; }
        }

        /// <summary>
        /// Photo description property
        /// Returns string description.
        /// Written By: Steven Gonzalez & Adam Reaves
        /// </summary>
        public string PhotoDescription
        {
            get { return photoDescription; }
        }
        /// <summary>
        /// Photo valid property
        /// Is only set true when validate form passes
        /// Written By: Steven Gonzalez & Adam Reaves
        /// </summary>
        public Boolean Valid
        {
            get { return validFlag; }
        }

        /// <summary>
        /// This function keeps track of the album desciption length.
        /// A character counter is updated when the text count changes.
        /// Written By: Steven Gonzalez
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void PhotoDescriptionTextBox_TextChanged(object sender, EventArgs e)
        {
            descripCharCounter.Text = "CHARS LEFT: " +
                (DESCRIP_COUNT - PhotoDescriptionTextBox.TextLength);
        }

        /// <summary>
        /// This function keeps track of the album name length.
        /// A character counter is updated when the text count changes.
        /// Written By: Steven Gonzalez
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void PhotoNameTextBox_TextChanged(object sender, EventArgs e)
        {
            nameCharCounter.Text = "CHARS LEFT: " +
                (NAME_COUNT - PhotoNameTextBox.TextLength);
        }
        /// <summary>
        /// This function selects the proper photo for selection.
        /// The GUI will have the proper photo selected.
        /// Written By: Steven Gonzalez & Adam Reaves
        /// </summary>
        private void AcceptPhotoButton_Click(object sender, EventArgs e)
        {
            this.AcceptForm();
        }
        /// <summary>
        /// called when cancel button is clicked
        /// Written By: Steven Gonzalez & Adam Reaves
        /// </summary>
        private void CancelCreationButton_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        /// <summary>
        /// called when clear button is clicked
        /// Written By: Steven Gonzalez & Adam Reaves
        /// </summary>
        private void ClearButton_Click(object sender, EventArgs e)
        {
            this.ClearForm();
        }
        /// <summary>
        /// called when clear button is clicked
        /// Written By: Steven Gonzalez & Adam Reaves
        /// </summary>
        private void ClearForm()
        {
            PhotoDescriptionTextBox.Text = "";
            PhotoNameTextBox.Text = "";
        }
    }
}
